package composite

import "fmt"

type Folder struct {
	// 组合模式的主要点，自身实现接口，属性也实现接口
	components []component
	name string
}

func (f *Folder) SetName(name string) {
	f.name = name
}

func (f *Folder) Search(keyword string) {
	fmt.Printf("Searching recursively for keyword %s in folder %s\n", keyword, f.name)
	for _, composite := range f.components {
		composite.Search(keyword)
	}
}

func (f *Folder) Add(c component)  {
	f.components = append(f.components, c)
}
